package ch.christianschweizer.apps.ereservation.model;

import javax.persistence.Basic;
import javax.persistence.Embeddable;

@Embeddable
public class Address {

	public static class AddressBuilder {

		private String street;
		private String zip;
		private String city;

		public AddressBuilder street(String street) {
			this.street = street;
			return this;
		}

		public AddressBuilder zip(String zip) {
			this.zip = zip;
			return this;
		}

		public AddressBuilder city(String city) {
			this.city = city;
			return this;
		}

		public Address build() {
			return new Address(this);
		}

	}

	@Basic
	private String street;

	@Basic
	private String zip;

	@Basic
	private String city;

	protected Address() {
	}

	private Address(AddressBuilder builder) {
		street = builder.street;
		zip = builder.zip;
		city = builder.city;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	@Override
	public String toString() {
		return "Address [street=" + street + ", zip=" + zip + ", city=" + city
				+ "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result + ((street == null) ? 0 : street.hashCode());
		result = prime * result + ((zip == null) ? 0 : zip.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Address other = (Address) obj;
		if (city == null) {
			if (other.city != null) {
				return false;
			}
		} else if (!city.equals(other.city)) {
			return false;
		}
		if (street == null) {
			if (other.street != null) {
				return false;
			}
		} else if (!street.equals(other.street)) {
			return false;
		}
		if (zip == null) {
			if (other.zip != null) {
				return false;
			}
		} else if (!zip.equals(other.zip)) {
			return false;
		}
		return true;
	}

}
